package com.tianqu.tms.www.cardect.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.entity.TmsDetectInfo;

/**
 * 待确认 单条提交到检测完了Controller
 * 
 * @author tianshifu
 * 
 */
public class CarWCToDectOverResultController extends TmsController {
	private Logger logger = Logger
			.getLogger(CarWCToDectOverResultController.class);// log
	private static final String CARSERIAL = "carSerial";// 车辆ID

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();

			// 从uc中获取车辆ID
			String carSerial = (String) uc.getAttribute(CARSERIAL);
			uc.removeAttribute(CARSERIAL);

			// 根据车辆ID更新车辆状态
			TmsDetectInfo entity = TmsDetectInfo.getInstance();
			entity.updateCarStatus(carSerial, TmsDetectInfo.DETECT_DATA_EXPORT);// 信息确认完了

			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#doAction was completed.");

	}

}
